import tensorflow as tf

# 统计

# L2 norm 2范数

a = tf.ones([3, 3])
n = tf.norm(a)
print(n)
n = tf.sqrt(tf.reduce_sum(tf.square(a)))
print(n)

a = tf.ones([3, 28, 28, 3])
n = tf.norm(a)
print(n)
n = tf.sqrt(tf.reduce_sum(tf.square(a)))
print(n)

# min/max/mean
a = tf.random.normal([5, 4])
print(a)
print(tf.reduce_min(a))
print(tf.reduce_max(a))
print(tf.reduce_mean(a))

print(tf.reduce_min(a, axis=1))
print(tf.reduce_max(a, axis=1))
print(tf.reduce_mean(a, axis=1))

# argmin/argmax
a = tf.random.normal([5, 4])
print(a)
print(tf.argmin(a))
print(tf.argmax(a))

# equal
a = tf.constant([1, 2, 4, 8])
b = tf.range(4)
print(tf.equal(a, b))

# unique/gather
a = tf.constant([2, 3, 3, 4, 5, 2])
b = tf.unique(a)
print(a)
print(b)
print(tf.gather(b[0], b[1]))
